home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / MCASM.RAR / MC_ASM.EXE / WROX_ASM / CH13 / TEST_UMB.ASM < prev   
Assembly Source File  |  1994-11-14  |  3KB  |  87 lines

  1. ; This dummy program is a template for correct usage of upper memory
  2. ; using DOS functions and strategies.
  3. ; Demo program for ExpAsm Chapter 13 Memory Management under 1Mb
  4. ; written by Yuri Kisselev. Autumn 1991 - Summer 1994 ^Z Minsk.
  5.  
  6. .286
  7. dosseg
  8. .model small
  9. .stack 100h
  10. .data
  11.         ptr1      dw 0
  12.         save_str  dw 0
  13.         flag_link db 0
  14. .code
  15. Start:                                  ; starting address
  16.                 mov ax,@data
  17.                 mov ds,ax               ; Load data segent
  18.                 mov bx,ss
  19.                 sub bx,ax
  20.                 shl bx,4
  21.                 cli
  22.                 mov ss,ax               ; Load new stack pointer
  23.                 add sp,bx
  24.                 sti
  25.                 mov bx,sp
  26.                 add bx,15               ; round up to next paragraph
  27.                 shr bx,4
  28.                 add ax,bx
  29.                 mov bx,es
  30.                 sub ax,bx
  31.                 mov bx,ax
  32.                 mov ah,4ah
  33.                 int 21h                 ; Resize program memory block
  34.                 jc resize_error        
  35.  
  36.                 mov ax,5800h
  37.                 int 21h                 ; Get allocation strategy
  38.                 mov save_str,ax         ; Save it
  39.  
  40.                 mov ax,5802h
  41.                 int 21h                 ; Get upper-memory link
  42.                 mov flag_link,al        ; Save it
  43.  
  44.                 mov bx,80h              ; BX = first_fit_high
  45.                 mov ax,5801h
  46.                 int 21h                 ; Set allocation strategy
  47.                 jc bad_strategy         ; CF = 1 if error
  48.  
  49.                 mov ax,5803h
  50.                 mov bx,1                ; BX = link flag
  51.                 int 21h                 ; Set upper-memory link
  52.                 jc link_error           ; CF = 1 if error
  53.  
  54.                 mov bx,256              ; BX = size of block
  55.                 mov ah,48h
  56.                 int 21h                 ; Allocate memory block
  57.                 jc alloc_err            ; CF = 1 if error
  58.                 mov ptr1,ax
  59.  
  60.                 ; play with block
  61.                 ; . . .
  62.  
  63.                 mov es,ptr1
  64.                 mov ah,49h
  65.                 int 21h                 ; Free memory block
  66.                 jc free_error           ; CF = 1if error
  67.  
  68.                 mov bx,save_str
  69.                 mov ax,5801h
  70.                 int 21h                 ; Restore allocation strategy
  71.                 jc bad_strategy         ; CF = 1 if error
  72.  
  73.                 mov ax,5803h
  74.                 xor bx,bx
  75.                 mov bl,flag_link
  76.                 int 21h                 ; Restore flag link
  77.                 jc link_error           ; CF = 1 if error
  78.                 xor al,al               ; set zero termination code
  79. resize_error:
  80. alloc_err:
  81. bad_strategy:
  82. link_error:
  83. free_error:
  84.                 mov ah,4ch
  85.                 int 21h                 ; Exit
  86. end Start
  87.